package de.fzi.kasma.learner.genetic;

import de.fzi.kasma.learner.data.Dataset;
import de.fzi.kasma.learner.path.PathRefinement;
import ec.EvolutionState;
import ec.simple.SimpleInitializer;
import ec.util.Parameter;
import edu.unika.aifb.graphindex.index.IndexDirectory;
import edu.unika.aifb.graphindex.index.IndexReader;


/***
 *  This class is the initialzier for RL. Put all the data-related initialization code and attribures here
 * @author Veli Bicer
 *
 */
public class RLInitializer extends SimpleInitializer {

	// parameter for positive examples
    public static final String P_POS = "pos";
    // parameter for negative examples
    public static final String P_NEG = "neg";
    // parameter for index directory
    public static final String P_INDEX = "index";
    
	private Dataset m_ds;
	private IndexReader m_ir;
	private PathRefinement m_pr;
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 9093496510161112086L;

	@Override
	public void setup(EvolutionState state, Parameter base) {
		// TODO Auto-generated method stub
		super.setup(state, base);
		
		setupIndexReader(state,RLDefaults.base());
		setupDataset(state,RLDefaults.base());
		setupPathRefinement(state,RLDefaults.base());
		
		
		
	}

	private void setupPathRefinement(EvolutionState state, Parameter base) {

		try {
			m_pr=new PathRefinement(m_ir);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

	private void setupIndexReader(EvolutionState state, Parameter base) {
		// 
		String directory=state.parameters.getString(base.push(P_INDEX), null);
		try{
			m_ir = new IndexReader(new IndexDirectory(directory));			
		}catch(Exception e){
			e.printStackTrace();
		}
		
	}

	private void setupDataset(EvolutionState state, Parameter base) {
		// TODO Auto-generated method stub
		String pos=state.parameters.getString(base.push(P_POS), null);
		String neg=state.parameters.getString(base.push(P_NEG), null);
		
		try {
			m_ds=new Dataset(m_ir, pos, neg);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	public Dataset getDataset(){return m_ds;}
	public PathRefinement getPathRefinement(){return m_pr;}

}
